package bsi.vn.Data;

import java.util.ArrayList;

import bsi.vn.FirstApp.R;
import android.content.Context;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TicketAdapter extends BaseAdapter{
	private static ArrayList<TicketData> searchArrayList;
	private LayoutInflater mInflater;
	
	public TicketAdapter(Context context, ArrayList<TicketData> results) {
		  searchArrayList = results;
		  mInflater = LayoutInflater.from(context);
	}

	public TicketAdapter(TextWatcher textWatcher, ArrayList<TicketData> results) {
		// TODO Auto-generated constructor stub
		searchArrayList = results;
		mInflater = LayoutInflater.from((Context) textWatcher);
	}

	@Override
	public int getCount() {
		  return searchArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		  return searchArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		  return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
		   convertView = mInflater.inflate(R.layout.ticket_row, null);
		   holder = new ViewHolder();
		   holder.tvTicketId = (TextView) convertView.findViewById(R.id.trtvTicketId);
		   holder.tvTicketCode = (TextView) convertView.findViewById(R.id.trtvTicketNo);
		   holder.tvSerialNo = (TextView) convertView.findViewById(R.id.trtvSerialNo);
		   holder.tvAddress = (TextView) convertView.findViewById(R.id.trtvAddress);
		   
		   convertView.setTag(holder);
		} 
		else {
		   holder = (ViewHolder) convertView.getTag();
		}
		
		holder.tvTicketId.setText(String.valueOf(searchArrayList.get(position).getTicketId()));
		holder.tvTicketCode.setText(searchArrayList.get(position).getTicketCode());
		holder.tvSerialNo.setText(searchArrayList.get(position).getSerialNo());
		holder.tvAddress.setText(searchArrayList.get(position).getProvince());
		
		return convertView;
	}
	
	static class ViewHolder {
		  TextView tvTicketId;
		  TextView tvTicketCode;
		  TextView tvAddress;
		  TextView tvSerialNo;
	}
}
